package com.bdqn.dao.impl;

import com.bdqn.dao.PetDao;
import com.bdqn.entity.Pet;
import com.bdqn.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class PetDaoImpl implements PetDao {
    SqlSession sqlSession=null;
    //查询所有宠物信息
    @Override
    public List<Pet> getPetList() {
        sqlSession= MybatisUtil.getSqlSession();
        List<Pet> petList=sqlSession.getMapper(PetDao.class).getPetList();
        return petList;
    }

    //添加宠物信息
    @Override
    public int addPet(Pet pet) {
        sqlSession=MybatisUtil.getSqlSession();
        int count=sqlSession.getMapper(PetDao.class).addPet(pet);
        sqlSession.commit();
        return count;
    }

    //删除宠物信息
    @Override
    public int deletePet(Integer petId) {
        sqlSession=MybatisUtil.getSqlSession();
        int count=sqlSession.getMapper(PetDao.class).deletePet(petId);
        sqlSession.commit();
        return count;
    }

    //修改宠物信息
    @Override
    public int updatePet(Pet pet) {
        sqlSession=MybatisUtil.getSqlSession();
        int count=sqlSession.getMapper(PetDao.class).updatePet(pet);
        sqlSession.commit();
        return count;
    }

    //根据宠物品种查询信息
    @Override
    public Pet getPetByBreed(Integer Breed) {
        sqlSession=MybatisUtil.getSqlSession();
        Pet pet=sqlSession.getMapper(PetDao.class).getPetByBreed(Breed);
        return pet;
    }
}
